package com.aiyige.page.globalsearch.model;

import com.aiyige.model.User;
import com.aiyige.model.moment.entity.Moment;
import com.aiyige.page.globalsearch.adapter.SearchAdapter;
import com.aiyige.utils.HighLightWordUtil;

public class SearchData {
    public static final int TYPE_UNKNOWN = 0;
    public static final int TYPE_INFO = 1;
    public static final int TYPE_USER = 2;
    public static final int TYPE_VIDEO = 3;
    public static final int TYPE_LEARN_VIDEO = 4;
    public static final int TYPE_MAJOR_COURSE = 5;
    public static final int TYPE_SPECIAL_TOPIC = 6;
    public static final int TYPE_PHOTO = 7;

    Moment moment;
    User user;
    int type;

    public SearchData() {
    }

    private SearchData(Builder builder) {
        setMoment(builder.moment);
        setUser(builder.user);
        setType(builder.type);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public Moment getMoment() {
        return moment;
    }

    public void setMoment(Moment moment) {
        this.moment = moment;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public static final class Builder {
        private Moment moment;
        private User user;
        private int type;

        private Builder() {
            type = TYPE_UNKNOWN;
        }

        public Builder moment(Moment val) {
            moment = val;
            return this;
        }

        public Builder user(User val) {
            user = val;
            return this;
        }

        public Builder type(int val) {
            type = val;
            return this;
        }

        public SearchData build() {
            return new SearchData(this);
        }
    }

    public static SearchData parse(Moment moment, String searchWord) {
        int searchDataType;
        switch (moment.getSubject()) {
            case Moment.SUBJECT_ARTICLE:
                searchDataType = SearchData.TYPE_INFO;
                break;
            case Moment.SUBJECT_SPECIAL_TOPIC:
                searchDataType = SearchData.TYPE_SPECIAL_TOPIC;
                break;
            case Moment.SUBJECT_VIDEO_COURSE:
                searchDataType = SearchData.TYPE_LEARN_VIDEO;
                break;
            case Moment.SUBJECT_MAJOR_COURSE:
                searchDataType = SearchData.TYPE_MAJOR_COURSE;
                break;
            case Moment.SUBJECT_PHOTO:
                searchDataType = SearchData.TYPE_PHOTO;
                break;
            case Moment.SUBJECT_VIDEO:
                searchDataType = SearchData.TYPE_VIDEO;
                break;
            default:
                searchDataType = SearchData.TYPE_UNKNOWN;
                break;
        }
        moment.setTitle(HighLightWordUtil.highLight(moment.getTitle(), searchWord));
        return SearchData.newBuilder()
                .type(searchDataType)
                .moment(moment)
                .build();
    }

    public static SearchData parse(User user, String searchWord) {
        user.setAccount(HighLightWordUtil.highLight(user.getAccount(), searchWord));
        return SearchData.newBuilder()
                .type(SearchData.TYPE_USER)
                .user(user)
                .build();
    }


}
